﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PMSGSC.DAL;
using PMSGSC.BLL;
using DevExpress.XtraEditors;
namespace PMSGSC.App
{
    public partial class ucLoadJobDescription : UserControl
    {
        public ucLoadJobDescription()
        {
            InitializeComponent();
        }
        public bool isChanges;
        public int id;
        public void SetValue(string code, string name, string id)
        {
            txtCode.Text = code;
            txtName.Text = name;
            lbid.Text = id;
        }

        private void txtCode_Validating(object sender, CancelEventArgs e)
        {
            if (txtCode.Text != "")
            {
                JobDescription jobDescription = JobsDescription_BLL.GetDataByCode(txtCode.Text, frmMain.ship.Ship_ID);
                if (null == jobDescription)
                {
                    XtraMessageBox.Show("Component not exits!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    e.Cancel = true;
                }
                else
                {
                    txtCode.Text = jobDescription.CodeJD;
                    txtName.Text = jobDescription.NameJD;
                    lbid.Text = jobDescription.JobDescription_ID.ToString();
                }
            }
            else
            {
                txtCode.Text = "";
                txtName.Text = "";
                lbid.Text = "";
            }
        }

        private void txtName_Validating(object sender, CancelEventArgs e)
        {

            if (txtName.Text != "")
            {
                JobDescription jobDescription = JobsDescription_BLL.GetDataByName(txtName.Text, frmMain.ship.Ship_ID);
                if (null == jobDescription)
                {
                    XtraMessageBox.Show("Component not exits!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    e.Cancel = true;
                }
                else
                {
                    txtCode.Text = jobDescription.CodeJD;
                    txtName.Text = jobDescription.NameJD;
                    lbid.Text = jobDescription.JobDescription_ID.ToString();
                }
            }
            else
            {
                txtCode.Text = "";
                txtName.Text = "";
                lbid.Text = "";
            }
        }

        private void txtName_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            frmGridJosDescription descrip = new frmGridJosDescription();
            descrip.ShowDialog();
            if (null != descrip.JobDescription)
            {
                if (null == Job_BLL.TestExitsJobDescription(id, descrip.JobDescription.JobDescription_ID))
                {
                    txtCode.Text = descrip.JobDescription.CodeJD;
                    txtName.Text = descrip.JobDescription.NameJD;
                    lbid.Text = descrip.JobDescription.JobDescription_ID.ToString();
                    isChanges = true;
                }
                else
                {
                    XtraMessageBox.Show("Job exits!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
    }
}
